/**
 * 项目名：五位一体化工安全信息平台
 * 日期：    2019-12-07 13:44:18
 * Copyright (c) 2015- joysuch-版权所有
 */

package com.joysuch.wwyt.bp.service.impl;

import cn.zlg.common.util.CollectionUtils;
import com.joysuch.wwyt.bp.bean.*;
import com.joysuch.wwyt.bp.bean.BpEmergencyContingencyPlanListBean.Search;
import com.joysuch.wwyt.bp.entity.*;
import com.joysuch.wwyt.bp.entity.dsl.QBpEmergencyContingencyPlan;
import com.joysuch.wwyt.bp.entity.dsl.QBpEmergencyContingencyPlans;
import com.joysuch.wwyt.bp.entity.dsl.QBpEmergencyContingencyType;
import com.joysuch.wwyt.bp.entity.dsl.QBpEmergencyPeople;
import com.joysuch.wwyt.bp.enums.RegulationDocumentTypes;
import com.joysuch.wwyt.bp.repository.*;
import com.joysuch.wwyt.bp.service.BpEmergencyContingencyPlanService;
import com.joysuch.wwyt.bp.service.BpTaskListService;
import com.joysuch.wwyt.core.bean.BaseAttachmentBean;
import com.joysuch.wwyt.core.common.util.PageDataUtils;
import com.joysuch.wwyt.core.common.util.PageDataUtils.PageDataConvert;
import com.joysuch.wwyt.core.common.util.SimpleDateFormatCache;
import com.joysuch.wwyt.core.entity.BaseRole;
import com.joysuch.wwyt.core.entity.BaseTypeGroupItem;
import com.joysuch.wwyt.core.entity.BaseUser;
import com.joysuch.wwyt.core.exception.BusinessRestrictionsException;
import com.joysuch.wwyt.core.repository.BaseAttachmentRepoDao;
import com.joysuch.wwyt.core.repository.BaseRoleDao;
import com.joysuch.wwyt.core.repository.BaseTypeGroupItemDao;
import com.joysuch.wwyt.core.repository.BaseUserDao;
import com.joysuch.wwyt.core.service.BaseAttachmentRepositoryService;
import com.joysuch.wwyt.core.service.BizCodeGeneratorFacade;
import com.joysuch.wwyt.core.support.Context;
import com.joysuch.wwyt.mh.entity.MhMajorHazard;
import com.joysuch.wwyt.mh.repository.MhMajorHazardDao;
import com.joysuch.wwyt.monitoringcenter.bean.CenterEmergencyPlanBean;
import com.querydsl.core.types.ExpressionUtils;
import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.dsl.BooleanExpression;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;

@Service
@Transactional
@Slf4j
public class BpEmergencyContingencyPlanServiceImpl implements BpEmergencyContingencyPlanService {

    @Autowired
    private BpTaskListService taskListService;
    @Autowired
    private BpTaskListDao taskListDao;
    @Autowired
    private BpEmergencyContingencyPlanDao dao;
    @Autowired
    private BizCodeGeneratorFacade bizCodeGeneratorFacade;
    @Autowired
    private BaseUserDao baseUserDao;
    @Autowired
    private BaseAttachmentRepoDao attachmentRepositoryDao;
    @Autowired
    private BaseAttachmentRepositoryService attachmentRepositoryService;
    @Autowired
    private BpDepartDao bpDepartDao;
    @Autowired
    private MhMajorHazardDao mhMajorHazardDao;
    @Autowired
    private BpEmergencyContingencyTypeDao bpEmergencyContingencyTypeDao;
    @Autowired
    private BpEmergencyContingencyPlansDao bpEmergencyContingencyPlansDao;
    @Autowired
    private BpEmergencyExercisePlanDao bpEmergencyExercisePlanDao;
    @Autowired
    private BpEmergencyPeopleDao bpEmergencyPeopleDao;
    @Autowired
    private BaseRoleDao baseRoleDao;
    @Autowired
    private BpJobDao bpJobDao;
    @Autowired
    private BaseTypeGroupItemDao baseTypeGroupItemDao;

    @Value("${wwyt.base.serverUrl}")
    private String serverUrl;

    @Override
    public BpEmergencyContingencyPlan add(BpEmergencyContingencyPlanEditBean entity) throws Exception {
        String name = entity.getName();
        List<BpEmergencyContingencyPlan> tempList = dao.findByName(name);
        if (!CollectionUtils.isEmpty(tempList)) {
            throw new IllegalArgumentException("此名称已存在");
        }
        BpEmergencyContingencyPlan content = new BpEmergencyContingencyPlan();
        // 预案名称
        content.setName(entity.getName());
        // 预案编号
        content.setCode(bizCodeGeneratorFacade.yingjiyuan());
        // 编制部门ID
        content.setMakeDepartId(entity.getMakeDepartId());
        // 编制人
        content.setMakeUserId(entity.getMakeUserId());
        // 发布时间
        content.setMakeTimeStart(entity.getMakeTimeStart());
        content.setMakeTimeEnd(entity.getMakeTimeEnd());
        // 适用范围
        content.setApplicationScope(entity.getApplicationScope());
        // 事故风险分析
        content.setAccidentRiskAnalysis(entity.getAccidentRiskAnalysis());
        // 应急处置措施
        content.setEmergencyMeasures(entity.getEmergencyMeasures());
        // 附件ID
        content.setAttachmentId(entity.getAttachmentId());
        // 状态
        content.setState(RegulationDocumentTypes.TO_BE_AUDITED.getId());
        // 演练级别
        content.setActLevel(entity.getActLevel());
        // 演练方式
        content.setActMethod(entity.getActMethod());

        BpEmergencyContingencyPlan save = dao.save(content);
        //saveTaskList("预案编制", save);
        return save;

    }

    private void saveTaskList(String module, BpEmergencyContingencyPlans save) {
        // 添加代办事项
        BpTaskList bpTaskList = new BpTaskList();
        bpTaskList.setDataId(save.getId());
        bpTaskList.setUserId(save.getMakeUserId());
        bpTaskList.setModule(module);
        taskListDao.save(bpTaskList);
    }

    @Override
    public void update(BpEmergencyContingencyPlanEditBean entity) throws Exception {
        BpEmergencyContingencyPlan content = dao.findById(entity.getId()).get();
        if (entity != null) {
            String name = entity.getName();
            if (!content.getName().equals(name)) {
                List<BpEmergencyContingencyPlan> tempList = dao.findByName(name);
                if (!CollectionUtils.isEmpty(tempList)) {
                    throw new IllegalArgumentException("此名称已存在");
                }
            }
            // 预案名称
            content.setName(entity.getName());
            // 编制部门ID
            content.setMakeDepartId(entity.getMakeDepartId());
            // 编制人
            content.setMakeUserId(entity.getMakeUserId());
            // 发布时间
            content.setMakeTimeStart(entity.getMakeTimeStart());
            content.setMakeTimeEnd(entity.getMakeTimeEnd());
            // 适用范围
            content.setApplicationScope(entity.getApplicationScope());
            // 事故风险分析
            content.setAccidentRiskAnalysis(entity.getAccidentRiskAnalysis());
            // 应急处置措施
            content.setEmergencyMeasures(entity.getEmergencyMeasures());
            // 附件ID
            if (entity.getAttachmentId() != null) {
                content.setAttachmentId(entity.getAttachmentId());
            }
            // 演练级别
            content.setActLevel(entity.getActLevel());
            // 演练方式
            content.setActMethod(entity.getActMethod());
            // 重置状态为待申请
            content.setState(RegulationDocumentTypes.TO_BE_AUDITED.getId());
            // 重置审核相关参数
            content.setAuditUserId(null);
            content.setAuditTime(null);
            content.setAuditRemark(null);
            BpEmergencyContingencyPlan save = dao.save(content);
            // saveTaskList("预案编制", save);
        }
    }

    @Override
    public Page<BpEmergencyContingencyPlanListBean> findByPage(Pageable page, Search condition) {
        Predicate predicate = prepareListSearchCondition(condition);
        page = PageDataUtils.addOrderByDesc(page, "id");
        Page<BpEmergencyContingencyPlan> data = predicate == null ? dao.findAll(page) : dao.findAll(predicate, page);

        return PageDataUtils.convertPageData(data,
                new PageDataConvert<BpEmergencyContingencyPlanListBean, BpEmergencyContingencyPlan>() {

                    @Override
                    public BpEmergencyContingencyPlanListBean convert(BpEmergencyContingencyPlan f) {
                        BpEmergencyContingencyPlanListBean bean = new BpEmergencyContingencyPlanListBean();

                        // ID，主键
                        bean.setId(f.getId());
                        // 预案名称
                        bean.setName(f.getName());
                        // 预案编号
                        bean.setCode(f.getCode());
                        // 编制部门ID
                        bean.setMakeDepartId(f.getMakeDepartId());
                        // 编制部门名称
                        if (f.getMakeDepartId() != null) {
                            BpDepart depart = bpDepartDao.findById(f.getMakeDepartId()).get();
                            bean.setMakeDepartName(depart.getName());
                        }

                        // 编制人
                        if (f.getMakeUserId() != null) {
                            bean.setMakeUserId(f.getMakeUserId());
                            String baseUserNameById = baseUserDao.getBaseUserNameById(f.getMakeUserId());
                            if (baseUserNameById != null) {
                                bean.setMakeUserName(baseUserNameById);
                            }
                        }
                        // 发布时间
                        if (f.getMakeTimeStart() != null) {
                            bean.setMakeTimeStart(SimpleDateFormatCache.getYmd().format(f.getMakeTimeStart()));
                        }
                        if (f.getMakeTimeEnd() != null) {
                            bean.setMakeTimeEnd(SimpleDateFormatCache.getYmd().format(f.getMakeTimeEnd()));
                        }
                        // 适用范围
                        bean.setApplicationScope(f.getApplicationScope());
                        // 事故风险分析
                        bean.setAccidentRiskAnalysis(f.getAccidentRiskAnalysis());
                        // 应急处置措施
                        bean.setEmergencyMeasures(f.getEmergencyMeasures());
                        // 状态
                        bean.setState(f.getState());
                        bean.setStateName(RegulationDocumentTypes.findByID(f.getState()).getName());
                        // 附件对象 [附件 ID 、附件名称、下载地址]
                        bean.setBaseAttachmentBean(findManyAttachmentByIdGroup(f.getAttachmentId()));
                        // 审核人
                        if (f.getAuditUserId() != null) {
                            bean.setAuditUserId(f.getAuditUserId());
                            bean.setAuditUserName(baseUserDao.findById(f.getAuditUserId()).get().getRealName());
                        }
                        // 审核时间
                        if (f.getAuditTime() != null) {
                            bean.setAuditTime(SimpleDateFormatCache.getYmdhms().format(f.getAuditTime()));
                        }
                        bean.setActLevel(f.getActLevel());
                        bean.setActMethod(f.getActMethod());
                        // 审核备注
                        bean.setAuditRemark(f.getAuditRemark());
                        return bean;
                    }

                });
    }

    private List<BaseAttachmentBean> findManyAttachmentByIdGroup(String idGroupString) {
        List<BaseAttachmentBean> list = new ArrayList<>(1);
        if (idGroupString != null) {
            String[] ids = idGroupString.split(",");
            for (String s : ids) {
                if (StringUtils.isNotBlank(s)) {
                    BaseAttachmentBean attachment = attachmentRepositoryService.findByIdIntoBean(Long.parseLong(s));
                    list.add(attachment);
                }
            }
        }
        return list;
    }

    private Predicate prepareListSearchCondition(Search condition) {
        QBpEmergencyContingencyPlan qEmePlan = QBpEmergencyContingencyPlan.bpEmergencyContingencyPlan;
        Predicate predicate = null;
        if (condition.getName() != null) {
            predicate = qEmePlan.name.like("%" + condition.getName() + "%");
        }
        if (condition.getState() != null) {
            String stateStr = condition.getState();
            if (stateStr.equals("planAudit")) { // 预案评审：[等待审核、审核不通过]
                BooleanExpression in = qEmePlan.state.in(RegulationDocumentTypes.AUDIT_WAIT.getId(),
                        RegulationDocumentTypes.AUDIT_FAILED.getId());
                predicate = ExpressionUtils.and(predicate, in);
            } else if (stateStr.equals("planArchive")) { // 预案制度：[审核通过]
                BooleanExpression eq = qEmePlan.state.eq(RegulationDocumentTypes.AUDIT_PASS.getId());
                predicate = ExpressionUtils.and(predicate, eq);
            }
        }
        if (condition.getMakeTimeStart() != null) {
            BooleanExpression eq = qEmePlan.makeTimeStart.goe(condition.getMakeTimeStart());
            predicate = ExpressionUtils.and(predicate, eq);
        }
        if (condition.getMakeTimeEnd() != null) {
            BooleanExpression eq = qEmePlan.makeTimeEnd.loe(condition.getMakeTimeEnd());
            predicate = ExpressionUtils.and(predicate, eq);
        }
        return predicate;
    }

    @Override
    public void delete(Long id) throws BusinessRestrictionsException {
        // 校验业务逻辑是否允许删除。如本数据被其他业务关联，删除后导致其他业务不可用。不能删除时将抛出业务异常
        checkBussinessRestrictions(id);
        dao.deleteById(id);
    }

    /**
     * 校验业务逻辑是否允许删除。如本数据被其他业务关联，删除后导致其他业务不可用
     *
     * @param id 要删除的业务ID
     * @throws BusinessRestrictionsException 抛出的业务异常
     */
    private void checkBussinessRestrictions(Long id) throws BusinessRestrictionsException {

    }

    @Override
    public BpEmergencyContingencyPlans findById(Long id) {
        //return dao.findById(id).get();
        return bpEmergencyContingencyPlansDao.findById(id).get();
    }

    @Override
    public BpEmergencyContingencyPlanDetailBean getById(Long id) {
        /*BpEmergencyContingencyPlans entity = findById(id);
        BpEmergencyContingencyPlanDetailBean bean = new BpEmergencyContingencyPlanDetailBean();
        // ID，主键
        bean.setId(entity.getId());

        // 预案名称
        bean.setName(entity.getName());

        // 预案编号
        bean.setCode(entity.getCode());

        // 编制部门ID
        bean.setMakeDepartId(entity.getMakeDepartId());
        // 编制部门名称
        BpDepart depart = bpDepartDao.findById(entity.getMakeDepartId()).get();
        bean.setMakeDepartName(depart.getName());

        // 编制人
        bean.setMakeUserId(entity.getMakeUserId());
        bean.setMakeUserName(baseUserDao.findById(entity.getMakeUserId()).get().getRealName());
        // 发布时间
        if (entity.getMakeTimeStart() != null) {
            bean.setMakeTimeStart(SimpleDateFormatCache.getYmdhms().format(entity.getMakeTimeStart()));
        }
        if (entity.getMakeTimeEnd() != null) {
            bean.setMakeTimeEnd(SimpleDateFormatCache.getYmdhms().format(entity.getMakeTimeEnd()));
        }
        // 适用范围
        bean.setApplicationScope(entity.getApplicationScope());
        // 事故风险分析
        bean.setAccidentRiskAnalysis(entity.getAccidentRiskAnalysis());
        // 应急处置措施
        bean.setEmergencyMeasures(entity.getEmergencyMeasures());
        // 状态
        bean.setState(entity.getState());
        // 演练级别
        bean.setActLevel(entity.getActLevel());
        // 演练方式
        bean.setActMethod(entity.getActMethod());
        bean.setStateName(RegulationDocumentTypes.findByID(entity.getState()).getName());
        // 审核人
        if (entity.getAuditUserId() != null) {
            bean.setAuditUserId(entity.getAuditUserId());
            bean.setAuditUserName(baseUserDao.findById(entity.getAuditUserId()).get().getRealName());
        }
        // 审核时间
        if (entity.getAuditTime() != null) {
            bean.setAuditTime(SimpleDateFormatCache.getYmdhms().format(entity.getAuditTime()));
        }
        // 审核备注
        bean.setAuditRemark(entity.getAuditRemark());

        // 附件对象 [附件 ID 、附件名称、下载地址]
        bean.setBaseAttachmentBean(findManyAttachmentByIdGroup(entity.getAttachmentId()));
        return bean;*/

        return null;
    }

    @Override
    public void changeState(Long id, Boolean isPass, String auditRemark) {
        // BpEmergencyContingencyPlan content = dao.findById(id).get();
        BpEmergencyContingencyPlans content = bpEmergencyContingencyPlansDao.findById(id).get();
        if (content != null) {
            if (content.getState() == RegulationDocumentTypes.TO_BE_AUDITED.getId()) {
                // 如果是待申请，则更新成等待审核
                content.setState(RegulationDocumentTypes.AUDIT_WAIT.getId());
                List<BpTaskList> byId = taskListService.findById(content.getId());
                if (byId != null) {
                    for (BpTaskList bpTaskList : byId) {
                        bpTaskList.setState(1);
                        bpTaskList.setDetail("预案评审");
                        bpTaskList.setHandleRemark("预案评审申请");
                        // 处理当前时间
                        bpTaskList.setHandleTime(new Date());
                        bpTaskList.setHandleUserId(Context.getCurrentUserId());
                        taskListDao.save(bpTaskList);
                    }
                }
            } else if (content.getState() == RegulationDocumentTypes.AUDIT_WAIT.getId()) {
                // 如果是等待审核，根据 isPass 更新
                if (isPass) { // 更新成审核通过
                    content.setAuditUserId(Context.getCurrentUserId());
                    content.setAuditRemaker(auditRemark);
                    content.setAuditTime(new Date());
                    content.setState(RegulationDocumentTypes.AUDIT_PASS.getId());
                    List<BpTaskList> byId = taskListService.findById(content.getId());
                    if (byId != null) {
                        for (BpTaskList bpTaskList : byId) {
                            bpTaskList.setState(2);
                            bpTaskList.setDetail("预案评审");
                            bpTaskList.setHandleRemark("预案评审申请");
                            // 处理当前时间
                            bpTaskList.setHandleTime(new Date());
                            bpTaskList.setHandleUserId(Context.getCurrentUserId());
                            taskListDao.save(bpTaskList);
                        }
                    }
                } else { // 更新成审核不通过
                    content.setAuditUserId(Context.getCurrentUserId());
                    content.setAuditRemaker(auditRemark);
                    content.setAuditTime(new Date());
                    content.setState(RegulationDocumentTypes.AUDIT_FAILED.getId());
                    List<BpTaskList> byId = taskListService.findById(content.getId());
                    if (byId != null) {
                        for (BpTaskList bpTaskList : byId) {
                            bpTaskList.setState(2);
                            bpTaskList.setDetail("预案评审");
                            bpTaskList.setHandleRemark("预案评审申请");
                            // 处理当前时间
                            bpTaskList.setHandleTime(new Date());
                            bpTaskList.setHandleUserId(Context.getCurrentUserId());
                            taskListDao.save(bpTaskList);
                        }
                    }
                }
            } else {
                // 其他状态，不进行更改
                return;
            }
            bpEmergencyContingencyPlansDao.save(content);
        }
    }

    /**
     * 新增预案类型
     *
     * @param bean
     * @return
     */
    @Override
    public BpEmergencyContingencyType addType(BpEmergencyContingencyTypeBean bean) {
        Long id = bpEmergencyContingencyTypeDao.findIdByName(bean.getName());
        if (id != null) {
            throw new IllegalArgumentException("预案类型已存在");
        }
        BpEmergencyContingencyType save = null;
        try {
            BpEmergencyContingencyType type = new BpEmergencyContingencyType();
            type.setName(bean.getName());
            type.setCount(0);
            save = bpEmergencyContingencyTypeDao.save(type);
        } catch (Exception e) {
            log.error("新增失败");
        }
        return save;
    }

    /**
     * 修改预案类型
     *
     * @param bean
     * @return
     */
    @Override
    public BpEmergencyContingencyType updateType(BpEmergencyContingencyTypeBean bean) {
        if (bean.getId() == null) {
            throw new IllegalArgumentException("预案类型不存在");
        }
        BpEmergencyContingencyType save = null;
        try {
            BpEmergencyContingencyType type = bpEmergencyContingencyTypeDao.findById(bean.getId()).get();
            type.setId(bean.getId());
            type.setName(bean.getName());
            type.setCount(bean.getCount());
            save = bpEmergencyContingencyTypeDao.save(type);
        } catch (Exception e) {
            log.error("修改失败");
        }
        return save;
    }

    /**
     * 删除预案类型
     *
     * @param id
     */
    @Override
    public void deleteType(Long id) {
        bpEmergencyContingencyTypeDao.deleteById(id);
    }

    /**
     * 分页预案类型
     *
     * @param page
     * @param condition
     * @return
     */
    @Override
    public Page<BpEmergencyContingencyTypeBean> pageType(Pageable page, BpEmergencyContingencyTypeBean.SearchType condition) {
        Predicate predicate = prepareListSearchConditionType(condition);
        page = PageDataUtils.addOrderByDesc(page, "id");
        Page<BpEmergencyContingencyType> data = predicate == null ? bpEmergencyContingencyTypeDao.findAll(page) : bpEmergencyContingencyTypeDao.findAll(predicate, page);
        return PageDataUtils.convertPageData(data, new PageDataConvert<BpEmergencyContingencyTypeBean, BpEmergencyContingencyType>() {
            @Override
            public BpEmergencyContingencyTypeBean convert(BpEmergencyContingencyType baseConfig) {
                BpEmergencyContingencyTypeBean bean = new BpEmergencyContingencyTypeBean();
                BeanUtils.copyProperties(baseConfig, bean);
                return bean;
            }
        });
    }

    private Predicate prepareListSearchConditionType(BpEmergencyContingencyTypeBean.SearchType condition) {
        Predicate p = null;
        QBpEmergencyContingencyType q = QBpEmergencyContingencyType.BpEmergencyContingencyType;
        if (condition.getId() != null) {
            p = ExpressionUtils.and(p, q.id.eq(condition.getId()));
        }
        if (condition.getCount() != null) {
            p = ExpressionUtils.and(p, q.count.eq(condition.getCount()));
        }
        if (condition.getName() != null) {
            p = ExpressionUtils.and(p, q.name.contains(condition.getName()));
        }
        return p;
    }


    /**
     * 获取预案类型列表
     *
     * @return
     */
    @Override
    public List<BpEmergencyContingencyType> findTypeList() {
        return bpEmergencyContingencyTypeDao.findAll();
    }

    /**
     * 增加预案
     *
     * @param bean
     * @return
     */
    @Override
    public BpEmergencyContingencyPlans addPlan(BpEmergencyContingencyPlansBean bean) {
        if (bean.getName() == null) {
            throw new IllegalArgumentException("预案名称不能为空");
        }
        List<BpEmergencyContingencyPlans> planNames = bpEmergencyContingencyPlansDao.findByName(bean.getName());
        if (!CollectionUtils.isEmpty(planNames)) {
            throw new IllegalArgumentException("预案名称已存在");
        }
        //将危险源,适用部门,应急成员,附件id转为String格式存入
        List<Long> hList = new ArrayList<>();
        List<Long> dList = new ArrayList<>();
        List<Long> emList = new ArrayList<>();
        if (bean.getHazards().size() > 0) {
            for (BpMhMajorHazardBean mBean : bean.getHazards()) {
                hList.add(mBean.getId());
            }
        }
        if (bean.getUseDeparts().size() > 0) {
            for (BpAddDepartBean bBean : bean.getUseDeparts()) {
                dList.add(bBean.getId());
            }
        }
        if (bean.getEmergencyMembers().size() > 0) {
            for (BpBaseUserBean uBean : bean.getEmergencyMembers()) {
                emList.add(uBean.getId());
            }
        }
        String hazardIds = longListToString(hList);
        String departIds = longListToString(dList);
        String emergencyMembers = longListToString(emList);
        String extractAttachmentIds = extractAttachmentIds(bean);

        BpEmergencyContingencyPlans plan = new BpEmergencyContingencyPlans();
        plan.setName(bean.getName());
        plan.setCode(bizCodeGeneratorFacade.yingjiyuan());
        plan.setUseDepartId(departIds);
        if (bean.getTypeId() == null) {
            throw new IllegalArgumentException("预案类型不能为空");
        }
        plan.setTypeId(bean.getTypeId());
        plan.setHazardId(hazardIds);
        plan.setPlanLevel(bean.getPlanLevel());
        plan.setReleaseDate(bean.getReleaseDate());
        plan.setEmergencyMember(emergencyMembers);
        plan.setContent(bean.getContent());
        plan.setNote(bean.getNote());
        plan.setMakeUserId(bean.getMakeUserId());
        plan.setMakeDepartId(bean.getMakeDepartId());
        plan.setAttachmentId(extractAttachmentIds);
        plan.setState(RegulationDocumentTypes.TO_BE_AUDITED.getId());
        BpEmergencyContingencyPlans save = bpEmergencyContingencyPlansDao.save(plan);
        saveTaskList("预案编制", save);
        //预案新增成功时 预案类型中的预案数量也增加
        BpEmergencyContingencyType type = bpEmergencyContingencyTypeDao.findById(save.getTypeId()).orElseThrow(() -> new IllegalArgumentException("预案类型不存在"));
        type.setCount(type.getCount() + 1);
        bpEmergencyContingencyTypeDao.save(type);
        return save;
    }

    /**
     * 修改预案计划
     *
     * @param bean
     * @return
     */
    @Override
    public BpEmergencyContingencyPlans updatePlan(BpEmergencyContingencyPlansBean bean) {
        if (bean.getName() == null) {
            throw new IllegalArgumentException("预案名称不能为空");
        }
        BpEmergencyContingencyPlans plan = bpEmergencyContingencyPlansDao.findById(bean.getId()).get();
        if (plan == null) {
            throw new IllegalArgumentException("预案不存在");
        }

        List<Long> hList = new ArrayList<>();
        List<Long> dList = new ArrayList<>();
        List<Long> emList = new ArrayList<>();
        if (bean.getHazards().size() > 0) {
            for (BpMhMajorHazardBean mBean : bean.getHazards()) {
                hList.add(mBean.getId());
            }
        }
        if (bean.getUseDeparts().size() > 0) {
            for (BpAddDepartBean bBean : bean.getUseDeparts()) {
                dList.add(bBean.getId());
            }
        }
        if (bean.getEmergencyMembers().size() > 0) {
            for (BpBaseUserBean uBean : bean.getEmergencyMembers()) {
                emList.add(uBean.getId());
            }
        }
        String hazardIds = longListToString(hList);
        String departIds = longListToString(dList);
        String emergencyMembers = longListToString(emList);
        String extractAttachmentIds = extractAttachmentIds(bean);
        plan.setId(bean.getId());
        plan.setName(bean.getName());
//        plan.setCode(bizCodeGeneratorFacade.yingjiyuan());
        plan.setUseDepartId(departIds);
        if (bean.getTypeId() == null) {
            throw new IllegalArgumentException("预案类型不能为空");
        }
        //修改预案类型统计数量
        if (!bean.getTypeId().equals(plan.getTypeId())) {
            BpEmergencyContingencyType newType = bpEmergencyContingencyTypeDao.findById(bean.getTypeId()).get();
            BpEmergencyContingencyType oldType = bpEmergencyContingencyTypeDao.findById(plan.getTypeId()).get();
            newType.setCount(newType.getCount() + 1);
            oldType.setCount(oldType.getCount() - 1);
            bpEmergencyContingencyTypeDao.save(newType);
            bpEmergencyContingencyTypeDao.save(oldType);
        }
        plan.setTypeId(bean.getTypeId());
        plan.setHazardId(hazardIds);
        plan.setPlanLevel(bean.getPlanLevel());
        plan.setEmergencyMember(emergencyMembers);
        plan.setContent(bean.getContent());
        plan.setNote(bean.getNote());
        plan.setMakeUserId(bean.getMakeUserId());
        plan.setMakeDepartId(bean.getMakeDepartId());
        plan.setAttachmentId(extractAttachmentIds);
        plan.setState(RegulationDocumentTypes.TO_BE_AUDITED.getId());
        // 重置审核相关参数
        plan.setAuditUserId(null);
        plan.setAuditTime(null);
        plan.setReleaseDate(bean.getReleaseDate());
        //plan.setNote(null);
        BpEmergencyContingencyPlans save = bpEmergencyContingencyPlansDao.save(plan);
        saveTaskList("预案编制", save);
        return save;
    }

    /**
     * 删除预案
     *
     * @param id
     */
    @Override
    public void deletePlan(Long id) {
        BpEmergencyContingencyPlans plan = bpEmergencyContingencyPlansDao.findById(id).get();
        //删除前判断演练计划是否使用了该预案,使用了则不进行删除操作
        List<BpEmergencyExercisePlan> pList = bpEmergencyExercisePlanDao.findByPid(id);
        if (pList != null && pList.size() > 0) {
            throw new IllegalArgumentException("演练计划已启用该预案,请勿删除");
        }
        bpEmergencyContingencyPlansDao.deleteById(id);
        //预案删除成功时 预案类型中的预案数量也减少
        BpEmergencyContingencyType type = bpEmergencyContingencyTypeDao.findById(plan.getTypeId()).get();
        type.setCount(type.getCount() - 1);
        bpEmergencyContingencyTypeDao.save(type);
    }

    /**
     * 查看预案
     *
     * @param id
     * @return
     */
    @Override
    public BpEmergencyContingencyPlansBean getPlan(Long id) {
        BpEmergencyContingencyPlans plan = bpEmergencyContingencyPlansDao.findById(id).get();
        BpEmergencyContingencyPlansBean bean = new BpEmergencyContingencyPlansBean();
        bean.setId(plan.getId());
        bean.setName(plan.getName());
        bean.setCode(plan.getCode());
        String useDepartId = plan.getUseDepartId();
        if (StringUtils.isNotBlank(useDepartId)) {
            String[] dString = useDepartId.split(",");
            List<BpAddDepartBean> useDeparts = new ArrayList<>();
            for (int j = 0; j < dString.length; j++) {
                Optional<BpDepart> obd = bpDepartDao.findById(Long.valueOf(dString[j].trim()));
                if (obd.isPresent()) {
                    BpDepart depart = obd.get();
                    BpAddDepartBean bpAddDepartBean = new BpAddDepartBean();
                    bpAddDepartBean.setId(depart.getId());
                    bpAddDepartBean.setName(depart.getName());
                    useDeparts.add(bpAddDepartBean);
                }
            }
            bean.setUseDeparts(useDeparts);
        } else {
            bean.setUseDeparts(null);
        }

        bean.setTypeId(plan.getTypeId());
        bean.setTypeName(bpEmergencyContingencyTypeDao.findById(plan.getTypeId()).get().getName());

        String mhMajorHazard = plan.getHazardId();
        if (StringUtils.isNotBlank(mhMajorHazard)) {
            String[] mString = mhMajorHazard.split(",");
            List<BpMhMajorHazardBean> hazards = new ArrayList<>();
            for (int j = 0; j < mString.length; j++) {
                Optional<MhMajorHazard> mho = mhMajorHazardDao.findById(Long.valueOf(mString[j].trim()));
                if (mho.isPresent()) {
                    BpMhMajorHazardBean bpMhMajorHazardBean = new BpMhMajorHazardBean();
                    bpMhMajorHazardBean.setId(mho.get().getId());
                    bpMhMajorHazardBean.setName(mho.get().getName());
                    hazards.add(bpMhMajorHazardBean);
                } else {
                    hazards.add(null);
                }

            }
            bean.setHazards(hazards);
        } else {
            bean.setHazards(null);
        }

        bean.setPlanLevel(plan.getPlanLevel());
        //预案级别
        if (plan.getPlanLevel() != null) {
            Optional<BaseTypeGroupItem> byId = baseTypeGroupItemDao.findById(plan.getPlanLevel());
            if (byId.isPresent()) {
                bean.setPlanLevelName(byId.get().getName());
            } else {
                bean.setPlanLevelName("");
            }
        }
        bean.setReleaseDate(plan.getReleaseDate());
        String emergencyMembers = plan.getEmergencyMember();
        if (StringUtils.isNotBlank(emergencyMembers)) {
            String[] eString = emergencyMembers.split(",");
            List<BpBaseUserBean> useDeparemergencyMembersts = new ArrayList<>();
            for (int j = 0; j < eString.length; j++) {
                Optional<BaseUser> bo = baseUserDao.findById(Long.valueOf(eString[j].trim()));
                if (bo.isPresent()) {
                    BpBaseUserBean bpBaseUserBean = new BpBaseUserBean();
                    bpBaseUserBean.setId(bo.get().getId());
                    bpBaseUserBean.setName(bo.get().getRealName());
                    useDeparemergencyMembersts.add(bpBaseUserBean);
                } else {
                    useDeparemergencyMembersts.add(null);
                }

            }
            bean.setEmergencyMembers(useDeparemergencyMembersts);
        } else {
            bean.setEmergencyMembers(null);
        }
        bean.setContent(plan.getContent());
        bean.setNote(plan.getNote());
        bean.setMakeUserId(plan.getMakeUserId());
        bean.setUserName(baseUserDao.findById(plan.getMakeUserId()).get().getRealName());
        bean.setMakeDepartId(plan.getMakeDepartId());
        bean.setDepartName(bpDepartDao.findById(plan.getMakeDepartId()).get().getName());
        bean.setAttachmentBeans(findManyAttachmentByIdGroup(plan.getAttachmentId()));
        bean.setState(plan.getState());
        bean.setStateName(getStateName(plan.getState()));
        bean.setAuditUserId(plan.getAuditUserId());

        if (plan.getAuditUserId() != null) {
            bean.setAuditUserName(baseUserDao.findById(plan.getAuditUserId()).get().getRealName());
        } else {
            bean.setAuditUserName(null);
        }
        bean.setAuditTime(plan.getAuditTime());
        bean.setAuditRemaker(plan.getAuditRemaker());
        return bean;
    }

    /**
     * 重新编制预案
     *
     * @param id
     */
    @Override
    public void rePlan(Long id) {
        BpEmergencyContingencyPlans plan = bpEmergencyContingencyPlansDao.findById(id).get();
        plan.setState(RegulationDocumentTypes.TO_BE_AUDITED.getId());
        plan.setAuditRemaker(null);
        plan.setAuditTime(null);
        bpEmergencyContingencyPlansDao.save(plan);
    }

    /**
     * 分页展示预案
     *
     * @param page
     * @param condition
     * @return
     */
    @Override
    public Page<BpEmergencyContingencyPlansBean> pagePlan(Pageable page, BpEmergencyContingencyPlansBean.SearchPlanBean condition) {
        Predicate predicate = prepareListSearchConditionPlan(condition);
        page = PageDataUtils.addOrderByDesc(page, "id");
        Page<BpEmergencyContingencyPlans> data = predicate == null ? bpEmergencyContingencyPlansDao.findAll(page) : bpEmergencyContingencyPlansDao.findAll(predicate, page);
        return PageDataUtils.convertPageData(data, new PageDataConvert<BpEmergencyContingencyPlansBean, BpEmergencyContingencyPlans>() {
            @Override
            public BpEmergencyContingencyPlansBean convert(BpEmergencyContingencyPlans baseConfig) {
                BpEmergencyContingencyPlansBean bean = new BpEmergencyContingencyPlansBean();
                BeanUtils.copyProperties(baseConfig, bean);
                if (bean.getTypeId() != null) {
                    Optional<BpEmergencyContingencyType> oct = bpEmergencyContingencyTypeDao.findById(bean.getTypeId());
                    if (oct.isPresent()) {
                        bean.setTypeName(oct.get().getName());
                    }
                } else {
                    bean.setTypeName(null);
                }

                if (bean.getMakeUserId() != null) {
                    Optional<BaseUser> obu = baseUserDao.findById(bean.getMakeUserId());
                    if (obu.isPresent()) {
                        bean.setUserName(obu.get().getRealName());
                    }
                } else {
                    bean.setUserName(null);
                }

                //预案级别
                if (baseConfig.getPlanLevel() != null) {
                    Optional<BaseTypeGroupItem> byId = baseTypeGroupItemDao.findById(baseConfig.getPlanLevel());
                    if (byId.isPresent()) {
                        bean.setPlanLevelName(byId.get().getName());
                    } else {
                        bean.setPlanLevelName("");
                    }
                }
                if (bean.getMakeDepartId() != null) {
                    Optional<BpDepart> obd = bpDepartDao.findById(bean.getMakeDepartId());
                    if (obd.isPresent()) {
                        bean.setDepartName(obd.get().getName());
                    }
                } else {
                    bean.setDepartName(null);
                }
                bean.setStateName(getStateName(bean.getState()));

                return bean;
            }
        });
    }

    /**
     * 增加应急人员
     *
     * @param bean
     * @return
     */
    @Override
    public BpEmergencyPeople addPeople(BpEmergencyPeopleBean bean) {
        List<BpEmergencyPeople> list = bpEmergencyPeopleDao.findByUserId(bean.getUserId());
        if (!CollectionUtils.isEmpty(list)) {
            throw new IllegalArgumentException("应急人员已存在");
        }
        BaseUser user = baseUserDao.findById(bean.getUserId()).orElseThrow(() -> new IllegalArgumentException("人员不存在"));
        BpEmergencyPeople ePeople = new BpEmergencyPeople();
        ePeople.setUserId(user.getId());
        bean.setUserName(user.getRealName());
        ePeople.setUserName(bean.getUserName());
        ePeople.setUserCode(user.getCode());
        ePeople.setJobId(user.getJob());
        ePeople.setDepartId(user.getDepartId());
        ePeople.setRoleId(user.getRole());
        ePeople.setPhoneNumber(user.getTelephone());
        //新增应急人员时默认-是
        String safetyTraining = "是";
        if (StringUtils.isNotBlank(bean.getSafetyTraining())) {
            safetyTraining = bean.getSafetyTraining();
        }
        ePeople.setSafetyTraining(safetyTraining);
        ePeople.setPeopleTypeId(bean.getPeopleTypeId());
        ePeople.setPositionId(bean.getPositionId());
        BpEmergencyPeople save = bpEmergencyPeopleDao.save(ePeople);
        return save;
    }

    /**
     * 修改应急队伍
     *
     * @param bean
     * @return
     */
    @Override
    public BpEmergencyPeople updatePeople(BpEmergencyPeopleBean bean) {
        BpEmergencyPeople people = bpEmergencyPeopleDao.findById(bean.getId()).orElseThrow(() -> new IllegalArgumentException("应急人员不存在"));
        people.setPeopleTypeId(bean.getPeopleTypeId());
        people.setPositionId(bean.getPositionId());
        people.setSafetyTraining(bean.getSafetyTraining());
        BpEmergencyPeople save = bpEmergencyPeopleDao.save(people);
        return save;
    }

    /**
     * 获取危险源关联的预案制度
     *
     * @param hazardId
     * @return
     */
    @Override
    public List<CenterEmergencyPlanBean> getPlanListByHazardId(Long hazardId) {
        List<CenterEmergencyPlanBean> list = new ArrayList<>();
        List<BpEmergencyContingencyPlans> plans = bpEmergencyContingencyPlansDao.findByState(RegulationDocumentTypes.AUDIT_PASS.getId());
        if (!CollectionUtils.isEmpty(plans)) {
            for (BpEmergencyContingencyPlans p : plans) {
                String mhMajorHazard = p.getHazardId();
                if (StringUtils.isNotBlank(mhMajorHazard)) {
                    String[] mString = mhMajorHazard.split(",");
                    for (String s : mString) {
                        if (String.valueOf(hazardId).equals(s)) {
                            CenterEmergencyPlanBean bean = new CenterEmergencyPlanBean();
                            bean.setId(p.getId());
                            bean.setName(p.getName());
                            if (p.getMakeUserId() != null) {
                                Optional<BaseUser> obu = baseUserDao.findById(p.getMakeUserId());
                                if (obu.isPresent()) {
                                    bean.setMakeUserName(obu.get().getRealName());
                                }
                            }
                            list.add(bean);
                            continue;
                        }
                    }
                }
            }
        }
        return list;
    }

    /**
     * 查看应急人员
     *
     * @param id
     * @return
     */
    @Override
    public BpEmergencyPeopleBean getPeopleById(Long id) {
        BpEmergencyPeople p = bpEmergencyPeopleDao.findById(id).orElseThrow(() -> new IllegalArgumentException("应急人员不存在"));
        BpEmergencyPeopleBean bean = new BpEmergencyPeopleBean();
        BeanUtils.copyProperties(p, bean);
        //人名
        bean.setUserName(p.getUserName());
        //身份
        if (p.getRoleId() != null) {
            Optional<BaseRole> obr = baseRoleDao.findById(p.getRoleId());
            if (obr.isPresent()) {
                bean.setRoleName(obr.get().getName());
            }
        }
        //部门
        if (p.getDepartId() != null) {
            Optional<BpDepart> obd = bpDepartDao.findById(p.getDepartId());
            if (obd.isPresent()) {
                bean.setDepartName(obd.get().getName());
            }

        }
        //岗位
        if (p.getJobId() != null) {
            Optional<BpJob> obj = bpJobDao.findById(p.getJobId());
            if (obj.isPresent()) {
                bean.setJobName(obj.get().getName());
            }
        }
        //应急人员类别名称
        if (p.getPeopleTypeId() != null) {
            bean.setPeopleTypeName(baseTypeGroupItemDao.getNameById(p.getPeopleTypeId()));
        }
        //应急职务名称
        if (p.getPositionId() != null) {
            bean.setPositionName(baseTypeGroupItemDao.getNameById(p.getPositionId()));
        }

        return bean;
    }

    /**
     * 分页查询应急人员
     *
     * @param page
     * @param condition
     * @return
     */
    @Override
    public Page<BpEmergencyPeopleBean> pagePeople(Pageable page, BpEmergencyPeopleBean.SearchPlanBean condition) {
        Predicate predicate = prepareListSearchConditionPeople(condition);
        page = PageDataUtils.addOrderByDesc(page, "id");
        Page<BpEmergencyPeople> data = predicate == null ? bpEmergencyPeopleDao.findAll(page) : bpEmergencyPeopleDao.findAll(predicate, page);
        return PageDataUtils.convertPageData(data, new PageDataConvert<BpEmergencyPeopleBean, BpEmergencyPeople>() {
            @Override
            public BpEmergencyPeopleBean convert(BpEmergencyPeople baseConfig) {
                BpEmergencyPeopleBean bean = new BpEmergencyPeopleBean();
                BeanUtils.copyProperties(baseConfig, bean);
                //身份
                if (baseConfig.getRoleId() != null) {
                    if (baseConfig.getRoleId() == 0) {
                        bean.setRoleName("员工");
                    }
                    if (baseConfig.getRoleId() == 1) {
                        bean.setRoleName("管理人员");
                    }
                    if (baseConfig.getRoleId() == 2) {
                        bean.setRoleName("企业负责人");
                    }
                }
                if (baseConfig.getRoleId() != null) {
                    Optional<BaseRole> obr = baseRoleDao.findById(baseConfig.getRoleId());
                    if (obr.isPresent()) {
                        bean.setRoleName(obr.get().getName());
                    }
                }
                //部门
                if (baseConfig.getDepartId() != null) {
                    Optional<BpDepart> obd = bpDepartDao.findById(baseConfig.getDepartId());
                    if (obd.isPresent()) {
                        bean.setDepartName(obd.get().getName());
                    }
                }
                //岗位
                if (baseConfig.getJobId() != null) {
                    Optional<BpJob> obj = bpJobDao.findById(baseConfig.getJobId());
                    if (obj.isPresent()) {
                        bean.setJobName(obj.get().getName());
                    }
                }
                //应急人员类别名称
                if (baseConfig.getPeopleTypeId() != null) {
                    bean.setPeopleTypeName(baseTypeGroupItemDao.getNameById(baseConfig.getPeopleTypeId()));
                }
                //应急职务名称
                if (baseConfig.getPositionId() != null) {
                    bean.setPositionName(baseTypeGroupItemDao.getNameById(baseConfig.getPositionId()));
                }
                if (baseConfig.getPhoneNumber()==null){
                    if (baseConfig.getUserId() != null) {
                        bean.setPhoneNumber(baseUserDao.getOne(baseConfig.getUserId()).getTelephone());
                    }
                }

                return bean;
            }
        });
    }


    /**
     * 删除应急人员
     *
     * @param id
     * @return
     */
    @Override
    public void deletePeople(Long id) {
        // checkPeople(id);
        bpEmergencyPeopleDao.deleteById(id);
    }

    //判断应急成员是否在已有应急预案中
    private void checkPeople(Long pId) {
        List<BpEmergencyContingencyPlans> all = bpEmergencyContingencyPlansDao.findAll();
        if (CollectionUtils.isNotEmpty(all)) {
            for (BpEmergencyContingencyPlans cPlan : all) {
                if (cPlan.getState() == 2) {
                    //跳过审核未通过的
                    continue;
                } else {
                    //演练计划是否使用了有该成员的预案制度
                    if (cPlan.getState() == 3) {
                        List<BpEmergencyExercisePlan> byPid = bpEmergencyExercisePlanDao.findByPid(cPlan.getId());
                        if (CollectionUtils.isNotEmpty(byPid)) {
                            throw new IllegalArgumentException("预案制度(" + cPlan.getCode() + ")中有该成员,已被演练计划使用,请勿删除");
                        }
                    }
                    //预案中应急队伍是否有该成员
                    if (StringUtils.isNotBlank(cPlan.getEmergencyMember())) {
                        String[] eString = cPlan.getEmergencyMember().split(",");
                        for (int j = 0; j < eString.length; j++) {
                            if (pId.equals(Long.valueOf(eString[j].trim()))) {
                                throw new IllegalArgumentException("预案(" + cPlan.getCode() + "),中有该成员,请勿删除");
                            }
                        }
                    }
                }
            }
        }
    }

    private Predicate prepareListSearchConditionPlan(BpEmergencyContingencyPlansBean.SearchPlanBean condition) {
        Predicate p = null;
        QBpEmergencyContingencyPlans q = QBpEmergencyContingencyPlans.BpEmergencyContingencyPlans;
        if (condition.getCodeOrName() != null) {
            p = ExpressionUtils.and(p, ExpressionUtils.or(q.code.like("%" + condition.getCodeOrName() + "%"),
                    q.name.like("%" + condition.getCodeOrName() + "%")));
        }
        if (condition.getTypeId() != null) {
            p = ExpressionUtils.and(p, q.typeId.eq(condition.getTypeId()));
        }
        if (condition.getPlanLevel() != null) {
            p = ExpressionUtils.and(p, q.planLevel.eq(condition.getPlanLevel()));
        }
        if (condition.getState() != null) {
            String stateStr = condition.getState();
            if (stateStr.equals("planAudit")) { // 预案评审：[等待审核、审核不通过]
                BooleanExpression in = q.state.in(RegulationDocumentTypes.AUDIT_WAIT.getId(),
                        RegulationDocumentTypes.AUDIT_FAILED.getId());
                p = ExpressionUtils.and(p, in);
            } else if (stateStr.equals("planArchive")) { // 预案制度：[审核通过]
                BooleanExpression eq = q.state.eq(RegulationDocumentTypes.AUDIT_PASS.getId());
                p = ExpressionUtils.and(p, eq);
            }
        }
        return p;
    }

    private Predicate prepareListSearchConditionPeople(BpEmergencyPeopleBean.SearchPlanBean condition) {
        Predicate p = null;
        QBpEmergencyPeople q = QBpEmergencyPeople.BpEmergencyPeople;
        if (condition.getNameOrCode() != null) {
            p = ExpressionUtils.and(p, ExpressionUtils.or(q.userCode.contains(condition.getNameOrCode()),
                    q.userName.contains(condition.getNameOrCode())));
        }
        return p;
    }

    /**
     * 附件上传处理
     *
     * @param entity
     */
    protected String extractAttachmentIds(BpEmergencyContingencyPlansBean entity) {
        if (entity.getAttachmentBeans() != null && entity.getAttachmentBeans().size() > 0) {
            StringBuilder sb = new StringBuilder();
            for (BaseAttachmentBean a : entity.getAttachmentBeans()) {
                sb.append(a.getId()).append(",");
            }
            sb.deleteCharAt(sb.length() - 1);
            return sb.toString();
        }
        return null;
    }

    /**
     * Long类型的list转String
     *
     * @param list
     * @return
     */
    private String longListToString(List<Long> list) {
        if (list.size() > 0) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < list.size(); i++) {
                sb.append(list.get(i)).append(",");
            }
            sb.deleteCharAt(sb.length() - 1);
            return sb.toString();
        } else {
            return null;
        }
    }

    /**
     * 预案状态id->name
     *
     * @param id
     * @return
     */
    private String getStateName(Integer id) {
        if (id == RegulationDocumentTypes.TO_BE_AUDITED.getId()) {
            return "待申请";
        } else if (id == RegulationDocumentTypes.AUDIT_WAIT.getId()) {
            return "等待审核";
        } else if (id == RegulationDocumentTypes.AUDIT_FAILED.getId()) {
            return "审核不通过";
        } else if (id == RegulationDocumentTypes.AUDIT_PASS.getId()) {
            return "审核通过";
        } else {
            return null;
        }
    }

}
